/*
 * Copyright 2009, 2010, YUNNAN Co-soft Information Technology Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * @author: Ruan Ao.
 * @version: May 19, 2010.
 **/
function showBigPic(tab){
    var divWidth = document.body.clientWidth;
    var divHight = document.body.clientHeight;
    currentPicTab=tab;
    var workPicDisplayer = document.getElementById("ourWorkDisplayer");
     $("#ourWorkDisplayerBg").css({
        "width":divWidth,
        "height":divHight
    });
    $(workPicDisplayer).find("img")[0].src="styles/images/work/work"+tab+"Big.jpg";
    $(workPicDisplayer).css("display","block");
     $("#ourWorkDisplayerBg").show();
    var left = (window.screen.width - workPicDisplayer.offsetWidth) / 2;
    // var top = (window.screen.height - workPicDisplayer.offsetHeight) / 2;
    $(workPicDisplayer).css("left",left);
    // $(workPicDisplayer).css("top",top);
    if (navigator.appVersion.indexOf("MSIE") != -1)
    {   // IE用attachEvent
        document.attachEvent("onclick", hideBigPic);
    }
    else{
        window.addEventListener("mousedown", hideBigPic, false);
    }
}

function hideBigPic(event){
    var target;
    var eventElementId;
    var parentId;
    if (navigator.appVersion.indexOf("MSIE") != -1)
    {   // IE用attachEvent
        target=event.srcElement;
    }
    else{
        target=event.target;
    }
    eventElementId = target.id;
    parentId = target.parentNode.id
    if(target.parentNode.tagName.toLowerCase() == "td"){
        parentId = target.parentNode.parentNode.parentNode.parentNode.id;
    }
    var workPicDisplayer = $("#ourWorkDisplayer");
    if((eventElementId == "closeBigPicButton") || ((eventElementId != "ourWorkPhotos") &&
        (parentId != "ourWorkPhotosList") && (eventElementId != "ourWorkDisplayer") &&
        (parentId != "workPhotosTool") && (eventElementId != "workPhotosTool"))){
        workPicDisplayer.css("display", "none");
         $("#ourWorkDisplayerBg").hide();
        if (navigator.appVersion.indexOf("MSIE") != -1)
        {   // IE用attachEvent
            window.detachEvent("event_handler",hideBigPic);
        }
        else{
            window.removeEventListener("mousedown", hideBigPic, false);
        }
    }
}

/*
 *显示前一张或者是下一张图片。
 **/
function gotoPic(tab){
    if(tab > picNumbers){
        tab=picNumbers;
    }
    else if( tab < 1){
        tab=1;
    }
    var workPicDisplayer = document.getElementById("ourWorkDisplayer");
    $(workPicDisplayer).find("img")[0].src="styles/images/work/work"+tab+"Big.jpg";
    currentPicTab=tab;
}
